﻿using System;

namespace DNT.RavenQA.Core.Extensions
{
    public static class RandomExtensions
    {
        const String AllowedChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@$^*()";

        public static String NextString(this Random random,
                                        Int32 length)
        {
            return NextString(random, AllowedChars, length, length);
        }

        public static String NextString(this Random random,
                                        Int32 minLength,
                                        Int32 maxLength)
        {
            return NextString(random, AllowedChars, minLength, maxLength);
        }

        public static String NextString(this Random random,
                                        String allowedChars,
                                        Int32 minLength,
                                        Int32 maxLength)
        {
            var chars = new Char[maxLength];
            var setLength = allowedChars.Length;

            var length = random.Next(minLength, maxLength + 1);

            for (var i = 0; i < length; ++i)
                chars[i] = allowedChars[random.Next(setLength)];

            return new String(chars, 0, length);
        }
    }
}